import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import VitePluginVueSetupExtend from "vite-plugin-vue-setup-extend";



export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue", "vue-router"],
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons/svg")],
      symbolId: "icon-[dir]-[name]",
    }),
    VitePluginVueSetupExtend(),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
  server: {
    port: 80,
    host: true,
    open: true,
    proxy: {
      // https://cn.vitejs.dev/config/#server-proxy
      "/dev-api": {
        target: "http://192.168.1.40:8080",
        // target: "http://192.168.1.40:8080",
        // target: "http://192.168.10.36:8080",
        // target: "https://app.hnlyzy.cn:6443/prod-api/",
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, ""),
      },
      "/dev-api2": {
        target: "http://sph-api.atguigu.cn",
        // target: 'https://heimahr.itheima.net',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api2/, ""),
      },
    },
  },
});
